package com.hhd.flow.configuration;

import com.tang.script.DefaultScriptEngine;
import com.tang.script.ScriptEngine;
import com.tang.script.command.CacheCommandManager;
import com.tang.script.command.DefaultCacheCommandManager;
import com.tang.script.command.ScriptCommandBuilder;
import com.tang.script.functions.DefaultCacheLoaderFunctionLoader;
import com.tang.script.functions.FunctionLoader;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ScriptEngineConfiguration {

    @Bean
    ScriptEngine scriptEngine() {
        DefaultScriptEngine engine = new DefaultScriptEngine();
        engine.setScriptCommandBuilder(scriptCommandBuilder());
        engine.setFunctionLoader(functionLoader());
        engine.setCacheCommandManager(cacheCommandManager());
        return engine;
    }

    ScriptCommandBuilder scriptCommandBuilder() {
        return new ScriptCommandBuilder();
    }

    FunctionLoader functionLoader() {
        return new DefaultCacheLoaderFunctionLoader();
    }

    CacheCommandManager cacheCommandManager() {
        return new DefaultCacheCommandManager();
    }
}
